package com.yunji.framework_template.orm.persistence.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.alibaba.fastjson.annotation.JSONField;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
 * 
 * 类Test.java的实现描述：TODO 类实现描述 
 * @author fenglibin1982@163.com
 * @Blog   http://blog.csdn.net/fenglibing 2018年10月13日 上午11:03:56
 */
@NoArgsConstructor
@AllArgsConstructor
//Builder注解主要用于对象的封装，使对像的set方法私有化，参考文章：https://www.cnblogs.com/lori/p/9024933.html
@Builder
@Entity
@Table(name="test")
//对所有的字段生成Getter和Setter方法、并可生成有有用的toString方法
@Data
@ToString
//只更新对象中有值的字段
@DynamicUpdate
//只插入对象中有值的字段
@DynamicInsert
//为了给modified字段自动赋值，详见https://www.jianshu.com/p/14cb69646195
@EntityListeners(AuditingEntityListener.class)
//该对象会用做swagger生成文档时解析为对应的对象参数
@ApiModel
public class Test {
    /*用于swagger生成文档时，对该字段的说明*/
    @ApiModelProperty(value="主键ID",example="123")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //建表的时候，要指定该字段为为主键及自增类型，如 "id int primary key not null auto_increment"
    private Integer id;

    /**
     *
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column test.val
     *
     * @mbg.generated Tue Sep 25 16:16:30 CST 2018
     */
    @ApiModelProperty(value="Val",example="val1")
    @NotNull
    @Builder.Default
    private String val="";
    
    /**
     * This field was generated by MyBatis Generator. This field corresponds to the database column test.big_type
     * @mbg.generated  Tue Sep 25 17:37:28 CST 2018
     */
    @ApiModelProperty("bigType")
    @NotNull
    @Column(name = "big_type",nullable = false,unique = false,length=32)
    private String bigType;
    /**
     * This field was generated by MyBatis Generator. This field corresponds to the database column test.small_type
     * @mbg.generated  Tue Sep 25 17:37:28 CST 2018
     */
    @ApiModelProperty("smallType")
    @NotEmpty
    @NotNull
    @Column(name = "small_type",nullable = false)
    private String smallType;
    
    @Column(updatable = false)
    @CreatedDate
    Date created;
    
    //FastJson解析该对象时，如果serialize为false，则不会返回该对象
    @JSONField(serialize=false)
    @LastModifiedDate
    private Date modified;
}